.NET Core中HttpReports快速搭建微服务
(给DotNet加星标,提升.Net技能)
转自:SpringLeee cnblogs.com/myshowtime/p/12747746.html
前言
HttpReports是针对.Net Core开发的轻量级APM系统,基于MIT开源协议, 使用HttpReports可以快速搭建.NET Core环境下统计,分析,图表,监控,分布式追踪一体化的站点, 适应.Net Core WebAPI,MVC,Web项目, 通过引用Nuget构建Dashboard面板,上手简单,适合在微服务架构中使用。
Github地址:https://github.com/SpringLeee/HttpReports
在线预览:https://moa.hengyinfs.com
账号: admin 密码 123456
开源不易,感兴趣的同学欢迎 Github Star 一波...
数据库支持
HttpReports Dashboard-UI
快速开始
Step1: 初始化数据库
引用成功后,因为我使用的是SqlServer 数据库,我们再Nuget引用 HttpReports.SqlServer 包
找到程序的 appsetting.json,修改为以下配置, 注意:这里Storage 配置的数据库名称要和新建的数据库名称一致
{
"HttpReports": {
"Storage": {
"ConnectionString": "Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;"
},
"Node": "UserService"
}
}
配置完成后,然后我们再修改 StartUp.cs 文件,修改为以下代码
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpReports().UseSQLServerStorage();
services.AddControllers();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHttpReports();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>{endpoints.MapControllers();});
}
引用完成后,修改Dahboard项目的 appsetting.json 文件, 注意数据库要一致
{
"HttpReportsDashboard": {
"Storage": {
"ConnectionString": "Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;"
}
}
}
修改完成后,我们接着修改 Dahboard 项目的 Startup.cs 文件
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpReportsDashboard().UseSQLServerStorage();
services.AddControllersWithViews();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseHttpReportsDashboard();
...
}
一切准备就绪后,我们启动Dashboard 项目,如果没有问题的话,会跳转到Dashboard的登陆页面
默认账号:admin 密码: 123456 , 登陆后可修改
修改startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddHttpReports().UseSQLServerStorage().UseGrpc();
services.AddControllersWithViews();
}
预警监控
HttpReports.Dashboard 集成了预警监控功能,使用的话需要先配置 Smtp 邮箱,否则接收不到预警邮件哦,
我们修改Dashboard项目的appsetting.json为下面即可
{
"HttpReportsDashboard": {
"Storage": {
"ConnectionString": "Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;"
},
"Mail": {
"Server": "smtp.qq.com",
"Port": 465,
"Account": "",
"Password": "",
"EnableSsL": true
}
}
}
{
"Title":"...",
"Content":"..."
}
最后,贴上两个完整的配置文件供大家参考
WebAPI端
{
"HttpReports": {
"Storage": {
"ConnectionString": "Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;",
"EnableDefer": false,
"DeferSecond": 20,
"DeferThreshold": 3
},
"Node": "UserService",
"Switch": true,
"FilterStaticFiles": true
}
}
{
"HttpReportsDashboard": {
"Storage": {
"ConnectionString": "Max Pool Size = 512;server=.;uid=sa;pwd=123456;database=HttpReports;"
},
"UseHome": true,
"ExpireDay":7,
"Mail": {
"Server": "smtp.qq.com",
"Port": 465,
"Account": "",
"Password": "",
"EnableSsL": true
}
}
}
参数说明:
UseHome Dashboard使用主页路由,默认为true,false 的话,路由为
localhost/Dashboard
ExpireDay 收集数据的有效期,默认30天
总结
HttpReports是.NET Core环境下开源的APM系统,非常适合微服务环境中使用,如果是中小型项目的话,那么使用 HttpReports 是一个不错的选择, 开源不易,如果能帮助到您的话,还请希望给个Star 支持下, 感谢
Github: https://github.com/SpringLeee/HttpReports
MIT协议:https://github.com/SpringLeee/HttpReports/blob/master/LICENSE
看完本文有收获?请转发分享给更多人
关注「DotNet」加星标,提升.Net技能
好文章,我在看❤️